﻿using GalaSoft.MvvmLight;

namespace Budgetsch.WP7.ViewModel.Saving
{
    using System;
    using System.Windows.Input;

    using Budgetsch.WP7.Navigation;
    using Budgetsch.WP7.WP7DataService;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight.Ioc;
    using GalaSoft.MvvmLight.Messaging;

    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class SavingListDetailsViewModel : ViewModelBase
    {
        private readonly Saving _saving;
        private readonly INavigationService _navigationService;

        public decimal Amount
        {
            get
            {
                return _saving.Amount;
            }
        }
        
        public string SavingCategoryName
        {
            get
            {
                return _saving.SavingCategory.Name;
            }
        }
        
        public string Comment
        {
            get
            {
                return _saving.Comment;
            }
        }

        public bool IsCommented
        {
            get
            {
                return _saving.SavingComments.Count > 0;
            }
        }

        public SavingListDetailsViewModel(Saving saving, INavigationService navigationService)
        {
            _saving = saving;
            _navigationService = navigationService;
        }

        public void NavigateToDetailsView()
        {
            SimpleIoc.Default.GetInstance<SavingDetailsViewModel>();
            Messenger.Default.Send(new LoadSavingDetailsViewMessage { Saving = _saving });
            SimpleIoc.Default.GetInstance<CommentWriterViewModel>();
            Messenger.Default.Send(new AddToUserNameMessage { UserName = _saving.User.UserName });
            _navigationService.NavigateTo(new Uri("/View/SavingDetailsView.xaml", UriKind.Relative));
        }
    }
}